<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="../../static/font-awesome-4.7.0/css/font-awesome.min.css" >
	<link rel="stylesheet" href="../../static/vui/css/vui.css">

	<script type="text/javascript" src="../../static/js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../../static/js/jquery.cookie.min.js"></script>
	<script type="text/javascript" src="../../static/layer/layer.js"></script>
	<script type="text/javascript" src="../../static/vui/js/vui.js"></script>
    <script type="text/javascript" src="../../static/vui/js/datagrid.js"></script>
	<script type="text/javascript" src="../../static/js/common.js"></script>
</head>
<body>


		<!--

		<tr>
			<td><label class="label required">---------------------------------------------------------</label></td>
			<td><input type="checkbox" name="test" autocomplete="off"/></td>
		</tr>

		<tr>
			<td><label class="label required">是否启用序列号管理</label></td>
			<td><input type="checkbox" name="code0000000004" autocomplete="off"/></td>
		</tr>
		<tr>
			<td><label class="label required">是否启用批次管理</label></td>
			<td><input type="checkbox" name="code0000000004" autocomplete="off"/></td>
		</tr>
		<tr>
			<td><label class="label required">是否启用分仓核算</label></td>
			<td><input type="checkbox" name="code0000000004" autocomplete="off"/></td>
		</tr>
		<tr>
			<td><label class="label required">是否启用零售</label></td>
			<td><input type="checkbox" name="code0000000004" autocomplete="off"/></td>
		</tr>
-->

<div id="formArea">
    <div class="ctx-title">
    	<div class="text"><b id="order_title">系统参数设置</b></div>
    	<div class="buttons">
    		<button class="button" id="create"><span>保存</span></button>
    	</div>
    </div>
    <div id="table"></div>
</div>

<script>

$(function () {
    $('#table').datagrid({
        pagination:false,
        width:800,
        url:app.BASE_API_URL+'dict/page',
        columns:[
            {field:'comments',align:'left',title:'功能',width:350,fixed:true,style:{"padding-left":"15px","text-align":"left"}},
            {field:'value',title:'操作',width:160,fixed:true,formatter:function (row) {
				if( row.code == '2000000003' ){
                    return '<div id="priceType"></div>';
				}else{
                    if( row.value == 0 ){
                        return '<input type="checkbox" tid="'+row.id+'"/>';
                    }else if( row.value == 1 ){
                        return '<input type="checkbox" checked="checked" tid="'+row.id+'"/>';
                    }
				}
			}},
            {field:'sm',title:'说明',align:'left',width:350,style:{"padding-left":"15px","text-align":"left"},formatter:function (row) {
				if( row.code == '2000000001' ){
					return '启用后单据只有在审核后才会生效';
				}else if( row.code == '2000000002' ){
					return '启用后可以负库存售货';
				}else if( row.code == '2000000003' ){
					return '销售计价方式';
				}else if( row.code == '2000000004' ){
                    return '';
                }else if( row.code == '2000000005' ){
                    return '新增商品、出入库等操作需要提供序列号';
                }else if( row.code == '2000000006' ){
                    return '保质期管理功能';
                }else if( row.code == '2000000007' ){
                    return 'SN码管理功能';
                }else if( row.code == '2000000008' ){
                    return '销售类单价为0时提示';
                }else if( row.code == '2000000009' ){
                    return '采购类单价为0时提示';
                }else if( row.code == '2000000010' ){
                    return '销售类单据日期不允许修改';
                }else if( row.code == '2000000011' ){
                    return '采购类单据日期不允许修改';
                }
			}}
        ],
        loadSuccess:loadDataSuccess
    });

});

$('#create').click(function () {
    var data = {};
    $('input[type="checkbox"]').each(function (i) {
        data['dicts['+i+'].id'] = $(this).attr('tid');
        if( $(this).prop("checked") ){
            data['dicts['+i+'].value'] = 1;
        }else{
            data['dicts['+i+'].value'] = 0;
        }
    });

    var len = $('input[type="checkbox"]').length;
    data['dicts['+len+'].id'] = 20002;
    data['dicts['+len+'].value'] = $('#priceType input[name="priceType"]').val();

    layer.confirm('修改基础参数需要重新加载界面，是否继续？', {icon: 3, title:'提示'}, function(index){
        app.request({
            url:'dict/update',
            data:data,
            success:function (resp) {
                if( resp.result == 0 ){
                    top.location.reload();
                }
            }
        });
    });
});

function loadDataSuccess() {
    $('#priceType').combobox({
        valueField:'id',textField:'name',width:100,
        name:'priceType',
        data:[{id:0,name:'移动平均法'},{id:1,name:'先进先出法'}]
    });

    var value = app.getDictValue(2000000003);
    if( value == 1 ){
        $('#priceType').combobox('setValue',1,'先进先出法');
    }else{
        $('#priceType').combobox('setValue',0,'移动平均法');
    }

}

</script>

</body>
</html>